from ctypes import cdll
import ctypes

#lib = cdll.LoadLibrary("/Users/trananh/Workspace/CC++/libdai/examples/bpwrapper.so")
#lib = cdll.LoadLibrary("/Users/tpilanta/Documents/workspace/libdai/examples/bpwrapper.so")
#lib = cdll.LoadLibrary("/home/tokutomi/Downloads/libdai/examples/bpwrapper.so")
#lib=cdll.LoadLibrary("/home/pr200/libdai/examples/bpwrapper.so")
lib = cdll.LoadLibrary("./dai/bpwrapper.so")
lib.newBP.restype = ctypes.c_void_p
lib.addVar.argtypes = [ctypes.c_void_p,ctypes.c_int]
lib.getJoint.argtypes = [ctypes.c_void_p,ctypes.c_int]
lib.getJoint.restype = ctypes.c_double
lib.dealloc.argyptes = [ctypes.c_void_p]
lib.run.argyptes = [ctypes.c_void_p]
lib.clamp.argtypes = [ctypes.c_void_p,ctypes.c_int,ctypes.c_bool]
lib.runMAP.argtypes = [ctypes.c_voidp];
lib.getStateMAP.argtypes = [ctypes.c_void_p,ctypes.c_int];
lib.getStateMAP.restype = ctypes.c_int;
lib.getLogScoreMAP.argtypes = [ctypes.c_void_p];
lib.getLogScoreMAP.restype = ctypes.c_double;
lib.getLogZ.argtypes = [ctypes.c_void_p];
lib.getLogZ.restype = ctypes.c_double;
lib.getStateMAP_Size.argtypes = [ctypes.c_void_p];
lib.getStateMAP_Size.restype = ctypes.c_int;

class BPwrapper(object):
    def __init__(self):
        self._as_parameter_ = self
#        print("in init")
        self.obj = lib.newBP()
#        print("initialized")
    def addVar(self,ind):
        if not (self.obj is None):
            lib.addVar(self.obj,ind)
    def getJoint(self,ind):
        if not (self.obj is None):
            return lib.getJoint(self.obj,ind)
    def run(self):
        if not (self.obj is None):
            lib.run(self.obj)
    def runMAP(self):
        if not (self.obj is None):
            lib.runMAP(self.obj)
    def getStateMAP(self, ind):
        if not (self.obj is None):
            return lib.getStateMAP(self.obj,ind);
    def getLogScoreMAP(self):
        if not (self.obj is None):
            return lib.getLogScoreMAP(self.obj);
    def getLogZ(self):
        if not (self.obj is None):
            return lib.getLogZ(self.obj);
    def getStateMAP_Size(self):
        if not (self.obj is None):
            return lib.getStateMAP_Size(self.obj);
    def dealloc(self):
        if not (self.obj is None):
            lib.dealloc(self.obj)
    def clamp(self,ind,val):
        if not (self.obj is None):
            lib.clamp(self.obj,ind,val)
    def resetClamps(self):
        if not (self.obj is None):
            lib.resetClamps(self.obj)
    def resetVars(self):
        if not (self.obj is None):
            lib.resetVars(self.obj)
